from typing import List, Optional, Any, Dict
from datetime import datetime
from uuid import UUID
from pydantic import BaseModel, Field

from app.core.document import DocumentStatus

# --- Document Schemas ---

class DocumentBase(BaseModel):
    filename: str
    status: DocumentStatus
    created_at: datetime
    metadata_: Optional[Dict[str, Any]] = Field(default=None, alias="metadata")

class DocumentResponse(DocumentBase):
    id: UUID
    minio_object_name: str

    class Config:
        from_attributes = True

class DocumentListResponse(BaseModel):
    total: int
    items: List[DocumentResponse]

# --- Chat Schemas ---

class ChatRequest(BaseModel):
    query: str = Field(..., min_length=1, description="User question")
    top_k: int = Field(5, ge=1, le=20, description="Number of chunks to retrieve")

class SourceDocument(BaseModel):
    filename: str
    page_content: str
    score: float = Field(..., description="Similarity score")
    metadata: Dict[str, Any] = Field(default_factory=dict)

class ChatResponse(BaseModel):
    answer: str
    sources: List[SourceDocument]

